package com.cgt.day6;

import org.junit.Test;

import java.util.*;

public class CollectionDemo {
    @Test
    public void test1(){
        Student[] student = new Student[3];
        List<Student> list1 = new ArrayList<>();
        Student student1 = new Student();
        Student student2 = new Student();
        Student student3 = new Student();
        Student student4 = new Student();
        list1.add(student1);
        list1.add(student2);
        list1.add(student3);
        list1.add(student4);
        list1.add(student1);

        ArrayList<String> list2 = new ArrayList<>();
//        List<String> list1 = new ArrayList<>();
        list2.add("Java");
        list2.add("UI");
        list2.add("H5");
        list2.add("H5");
        list2.add("Aa");
        for (String str1 : list2) {
            System.out.println(str1);
        }
        System.out.println();

        LinkedList linkedList = new LinkedList();
        linkedList.addFirst("A");
        linkedList.removeFirst();
        linkedList.addLast("B");
        linkedList.removeLast();

        Set<String> set = new HashSet<>();
        set.add("Java");
        set.add("UI");
        set.add("H5");
        set.add("H5");
        set.add("Aa");
        for (String str2 : set) {
            System.out.println(str2);
        }
    }

    public void test2(){
        // 创建Map对象
        Map<String, String> map = new HashMap<String, String>();
        // 给map中添加元素
        map.put("星期一", "Monday");
        map.put("星期日", "Sunday");
        System.out.println(map); // {星期日=Sunday, 星期一=Monday}
        // 根据指定的key获取对应的value
        String en = map.get("星期日");
        System.out.println(en); // Sunday
        // 根据key删除元素,会返回key对应的value值
        String value = map.remove("星期日");
        System.out.println(value); // Sunday
        System.out.println(map); // {星期一=Monday}
    }

    @Test
    public void test3(){
        Map<String,String> map = new HashMap<>();
        map.put("cn", "中国");
        map.put("us", "美国");
        map.put("uk", "英国");

        Set<String> keySet = map.keySet();
        for (String key : keySet) {
            System.out.println(key + ":" + map.get(key));
        }

        Set<Map.Entry<String,String>> entrySet = map.entrySet();
        for (Map.Entry<String, String> entry : entrySet) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
        }
    }
}
